package com.four.marketing.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.four.marketing.dao.CollageDao;
import com.four.marketing.entity.Collage;
import com.four.marketing.entity.Group;
import com.four.marketing.dao.GroupMapper;
import com.four.marketing.service.IGroupService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.four.marketing.vo.GroupVo;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author gs
 * @since 2021-12-16
 */
@Service
public class GroupServiceImpl extends ServiceImpl<GroupMapper, Group> implements IGroupService {

    @Autowired
    private GroupMapper groupMapper;

    @Autowired
    private CollageDao collageDao;

    @Autowired
    private RabbitTemplate rabbitTemplate;


    @Override
    public void addGroup(Integer id,String loginName) {
        //根据id去查询拼团商品信息
        Collage collage=collageDao.selectCollageById(id);
        //给拼团管理表赋值
        Group group = new Group();
        group.setGroImg(collage.getCoPicture());
        group.setGroUname(loginName);
        group.setGroStartTime(collage.getStartTime());
        group.setCoName(collage.getCoName());
        group.setGroProple(collage.getCoGroupSize());
        group.setGroAttend(collage.getNumberOfParticipants());
        group.setGroEndTime(collage.getEndTime());
        group.setGroStatus(0);
        Integer integer = groupMapper.addGroup(group);
        rabbitTemplate.convertAndSend("order-die",(group.getGroId()+""));
    }

    @Override
    public IPage<Group> groupList(GroupVo vo, Integer page, Integer size) {

        Page<Group> groupPage = new Page<>(page, size);
        return groupMapper.groupList(groupPage,vo);
    }

    @Override
    public void deleteById(Long id) {
        groupMapper.deleteById(id);
    }

    @Override
    public Group findById(Long id) {
        return groupMapper.findById(id);
    }
}
